#! /bin/sh
# PCP QA Test No. 198
# pv:934332 __pmdaMainPDU leaks pmProfile objects
#
# Copyright (c) 2005 Silicon Graphics, Inc.  All Rights Reserved.
#

seq=`basename $0`
echo "QA output created by $seq"

# get standard environment, filters and checks
. ./common.product
. ./common.filter
. ./common.check

status=0	# success is the default!
trap "rm -f $tmp.*; exit \$status" 0 1 2 3 15


# real QA test starts here

for pmda in sample sampledso
do
    echo "=== $pmda pmda ==="
    echo "=== $pmda pmda ===" >>$seq_full
    then=`pmprobe -v $pmda.datasize | $PCP_AWK_PROG '{print $NF}'`
    echo "then=$then" >>$seq_full

    for i in 1 2 3 4
    do
	pmval -t 20msec -s 250 -i "${i}10,${i}11,${i}12,${i}13,${i}14,${i}15,${i}16,${i}17,${i}18,${i}19,${i}20,${i}21,${i}22,${i}23,${i}24,${i}25,${i}26,${i}27,${i}28,${i}29,${i}30,${i}31,${i}32,${i}33,${i}34,${i}35,${i}36,${i}37,${i}38,${i}39,${i}40,${i}41,${i}42,${i}43,${i}44,${i}45,${i}46,${i}47,${i}48,${i}49,${i}50,${i}51,${i}52,${i}53,${i}54,${i}55,${i}56,${i}57,${i}58,${i}59" $pmda.hordes.one >$tmp.$i &
    done

    wait

    for i in 1 2 3 4
    do
	echo "thread $i: lines of output: `wc -l <$tmp.$i | sed -e 's/  *//g'`"
    done

    now=`pmprobe -v $pmda.datasize | $PCP_AWK_PROG '{print $NF}'`
    echo "now=$now" >>$seq_full
    delta=`expr $now - $then`

    # A 4 (Kbyte) slop is allowed for one-trip non-determinism for the
    # sample PMDA.
    # For the DSO PMDA we're really looking at pmcd's memory footprint
    # and there can be way more going on there, so be more relaxed and
    # 100 (Kbyte) slop seems to be needed.
    #
    if [ "$pmda" = sample ]
    then
	limit=4
    else
	limit=100
    fi
    if [ "$delta" -gt $limit ]
    then
	echo "Arrgh ... memory leak"
	echo "before: $then after: $now delta: $delta limit: $limit"
	status=1
    fi

    cat $tmp.1 >>$seq_full
done

exit

# all done
exit
